package com.cmccgz.udacs_landlord_webapp.main.housemanager.function;

import com.cmccgz.udacs_landlord_webapp.bean.BuildingCountBean;
import com.cmccgz.udacs_landlord_webapp.data.HouseManagerDataSource;
import com.cmccgz.udacs_landlord_webapp.data.HouseManagerRepository;

import java.util.List;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/2 16:50
 */

public class HouseRoomCountPresenter implements HouseFunctionContract.RoomCountPresenter {

    private HouseFunctionContract.RoomCountView mView;
    private HouseManagerRepository mRepository;

    public HouseRoomCountPresenter(HouseManagerRepository houseManagerRepository, HouseFunctionContract.RoomCountView fragment) {
        this.mRepository = houseManagerRepository;
        this.mView = fragment;
        this.mView.setPresenter(this);
    }

    @Override
    public void start() {
    }

    @Override
    public void getData(String buildingId) {
        if (mView.isActive()){
            mRepository.getBuildingCount(buildingId, new HouseManagerDataSource.BuildingCountCallback() {
                @Override
                public void onBuildingCountLoaded(List<BuildingCountBean> list) {
                    mView.getDataSuccess(list);
                }

                @Override
                public void onLoadedFailed(String msg) {
                    mView.getDataFailed(msg);
                }
            });
        }
    }
}
